<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>控制台页面_AmaAdmin后台管理系统模板</title>
<link rel="stylesheet" href="static/AmaAdmin/css/style.default.css" type="text/css" />
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery-1.7.min.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery.cookie.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery.uniform.min.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery.flot.min.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery.flot.resize.min.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/plugins/jquery.slimscroll.js"></script>
<script type="text/javascript" src="static/AmaAdmin/js/custom/general.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/static/angularjs/angular.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/static/angularjs/angular-route.min.js"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/plugins/excanvas.min.js"></script><![endif]-->
<!--[if IE 9]>
    <link rel="stylesheet" media="screen" href="css/style.ie9.css"/>
<![endif]-->
<!--[if IE 8]>
    <link rel="stylesheet" media="screen" href="css/style.ie8.css"/>
<![endif]-->
<!--[if lt IE 9]>
	<script src="js/plugins/css3-mediaqueries.js"></script>
<![endif]-->
</head>

<body class="withvernav">
<div class="bodywrapper">
    <div class="topheader">
        <div class="left">
            <h1 class="logo">Ama.<span>Admin</span></h1>
            <span class="slogan">后台管理系统</span>
            
            <div class="search">
            	<form action="" method="post">
                	<input type="text" name="keyword" id="keyword" value="请输入" />
                    <button class="submitbutton"></button>
                </form>
            </div><!--search-->
            
            <br clear="all" />
            
        </div><!--left-->
        
        <div class="right">
        	<!--<div class="notification">
                <a class="count" href="ajax/notifications.html"><span>9</span></a>
        	</div>-->
            <div class="userinfo">
            	<img src="images/thumbs/avatar.png" alt="" />
                <span>管理员</span>
            </div><!--userinfo-->
            
            <div class="userinfodrop">
            	<div class="avatar">
                	<a href=""><img src="images/thumbs/avatarbig.png" alt="" /></a>
                    <div class="changetheme">
                    	切换主题: <br />
                    	<a class="default"></a>
                        <a class="blueline"></a>
                        <a class="greenline"></a>
                        <a class="contrast"></a>
                        <a class="custombg"></a>
                    </div>
                </div><!--avatar-->
                <div class="userdata">
                	<h4>Juan</h4>
                    <span class="email">youremail@yourdomain.com</span>
                    <ul>
                    	<li><a href="editprofile.html">编辑资料</a></li>
                        <li><a href="accountsettings.html">账号设置</a></li>
                        <li><a href="help.html">帮助</a></li>
                        <li><a href="index.html">退出</a></li>
                    </ul>
                </div><!--userdata-->
            </div><!--userinfodrop-->
        </div><!--right-->
    </div><!--topheader-->
    
    
    <div class="header">
    	<ul class="headermenu">
        	<li class="current"><a href="dashboard.html"><span class="icon icon-flatscreen"></span>首页</a></li>
            <li><a href="manageblog.html"><span class="icon icon-pencil"></span>订单管理</a></li>
            <li><a href="messages.html"><span class="icon icon-message"></span>卡密库管理</a></li>
            <li><a href="reports.html"><span class="icon icon-chart"></span>统计报表</a></li>
        </ul>
        
    </div><!--header-->
    
    <div class="vernav2 iconmenu">
    	<ul>
        	<li><a href="#formsub" class="editor">表单提交</a>
            	<span class="arrow"></span>
            	<ul id="formsub">
               		<li><a href="#tables">卡密库维护</a></li>
                    <li><a href="wizard.html">表单验证</a></li>
                    <li><a href="editor.html">编辑器</a></li>
                </ul>
            </li>
            <!--<li><a href="filemanager.html" class="gallery">文件管理</a></li>-->
            <li><a href="elements.html" class="elements">网页元素</a></li>
        </ul>
        <a class="togglemenu"></a>
        <br /><br />
    </div><!--leftmenu-->
        
    <div class="centercontent">
        <div id="contentwrapper" class="contentwrapper">
        	<div ng-view></div>
        </div><!--contentwrapper-->
        <br clear="all" />
        
	</div><!-- centercontent -->
    
    
</div><!--bodywrapper-->

</body>

<script type="text/javascript">

	var myApp = angular.module('myApp',['ngRoute']);
	myApp.config(['$routeProvider','$httpProvider',function($routeProvider,$httpProvider){
		$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';     
		$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; 
		$httpProvider.defaults.transformRequest = [function(data) { 
		var param = function(obj) {             
			var query = '';             
			var name, value, fullSubName, subName, subValue, innerObj, i;              
			for (name in obj) {                
				value = obj[name];                  
				if (value instanceof Array) {               
					for (i = 0; i < value.length; ++i) {       
						subValue = value[i];               
						fullSubName = name + '[' + i + ']';         
						innerObj = {};             
						innerObj[fullSubName] = subValue;      
						query += param(innerObj) + '&';     
						}                 
					} else if (value instanceof Object) {          
						for (subName in value) {         
							subValue = value[subName];    
							fullSubName = name + '[' + subName + ']';     
							innerObj = {};              
							innerObj[fullSubName] = subValue;    
							query += param(innerObj) + '&';     
							}               
						} else if (value !== undefined && value !== null) {   
							query += encodeURIComponent(name) + '='    
							+ encodeURIComponent(value) + '&';                 
							}           
				}              
			return query.length ? query.substr(0, query.length - 1) : query;    
			};          
			return angular.isObject(data) && String(data) !== '[object File]'? param(data): data;    
			}]; 
		
	
		
		$routeProvider
			.when('/tables',{
				templateUrl:'page/cardManage/cardTable.html',
				controller:'tableController'
			})
			.when('/addNew/:id',{
				templateUrl:'page/cardManage/addCard.html',
				controller:'addNewController'
			});
	}]);
	
	myApp.controller('tableController', function($scope,$http,BusinessService,$location) {
		$scope.currentPage = 1;
	    $scope.totalPage = 1;
	    $scope.pageSize = 3;
	    $scope.pages = [];
	    $scope.endPage = 1;
	    //获取总流水
	    BusinessService.total().success(function (data) {
	        $scope.total = data;
	    });
	    
	    BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
	    	$scope.cards = data;
	    	$scope.totalPage = Math.ceil($scope.total/$scope.pageSize);
	    });
	 
	    $scope.load = function () {
	        BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
	            $scope.cards = data;
	            //获取总页数
	            //$scope.totalPage = Math.ceil(data.count / $scope.pageSize);
	            $scope.endPage = $scope.totalPage;
	            //生成数字链接
	            if ($scope.currentPage > 1 && $scope.currentPage < $scope.totalPage) {
	                $scope.pages = [
	                    $scope.currentPage - 1,
	                    $scope.currentPage,
	                    $scope.currentPage + 1
	                ];
	            } else if ($scope.currentPage == 1 && $scope.totalPage > 1) {
	                $scope.pages = [
	                    $scope.currentPage,
	                    $scope.currentPage + 1
	                ];
	            } else if ($scope.currentPage == $scope.totalPage && $scope.totalPage > 1) {
	                $scope.pages = [
	                    $scope.currentPage - 1,
	                    $scope.currentPage
	                ];
	            }
	        });
	    };
	 
	    $scope.next = function () {
	        if ($scope.currentPage < $scope.totalPage) {
	            $scope.currentPage++;
	            $scope.load();
	        }
	    };
	 
	    $scope.prev = function () {
	        if ($scope.currentPage > 1) {
	            $scope.currentPage--;
	            $scope.load();
	        }
	    };
	 
	    $scope.loadPage = function (page) {
	        $scope.currentPage = page;
	        $scope.load();
	    };
	    
	    $scope.checkClick = function(id,pd){
	    	alert(id);
	    	$scope.card_id = id;
	    }
	    
	    $scope.update= function (){
	    	$location.path("addNew/"+$scope.card_id);
	    }
	});

	
	myApp.factory('BusinessService', ['$http', function ($http) {
	    var list = function (page, size) {
	        return $http({
	            params: {
	                page: page,
	                size: size
	            },
	            url: '<%=request.getContextPath()%>/card/getOrder'
	        });
	    };
	 
	    var total = function () {
	        return $http.get('<%=request.getContextPath()%>/card/getTotal');
	    };
	 
	    var post = function (business) {
	        return $http.post('/merchants/business/post', business);
	    };
	 
	    return {
	        list: function (page, size) {
	            return list(page, size);
	        },
	        total: function () {
	            return total();
	        },
	        post: function (business) {
	            return post(business);
	        }
	    };
	}]);

	
	myApp.controller("addNewController",function($scope,$http,$location,$routeParams,$window){
		
		$http.get('<%=request.getContextPath()%>/card/updateRow/'+$routeParams.id).success(function (data){
			$scope.cardid = data.id;
			$scope.cardm = data.cardm;
			$scope.indate = data.in_date;
		});
		
		
		//更新
		$scope.addNew = function(){
			var pData = {cardid:$scope.cardid,cardm:$scope.cardm};
			$http({
				method:'POST',
				url: '<%=request.getContextPath()%>/card/saveOrder',
				data: pData,
				headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
				
	        }).success(function (data){
				$location.path("tables");
				toastr[data.flag](data.msg, data.title);
			});
		}
		
		$scope.reBack = function(){
			$window.history.back();
		}
		
	});

</script>


</html>